import { createRouter, createWebHistory } from 'vue-router'
import { useStore } from "@/stores/index.js"



const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior (to, from, savedPosition) {
    // always scroll to top
    return { top: 0 }
  },
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('../views/HomeView.vue'),
    },
    {
      path: '/city',
      name: 'city',
      component: () => import('../views/CityView.vue'),
    },

    {
      path: '/cinemas',
      name: 'cinemas',
      component: () => import('../views/CinemasView.vue'),
    },
    {
      path: '/cinema/:id',
      name: 'cinemaDetail',
      component: () => import('../views/CinemaDetail.vue'),
      props: true,
    },
    {
      path: '/film/:id',
      name: 'filmDetail',
      component: () => import('../views/FilmDetail.vue'),
      props: true,
    },

  ],
})


router.beforeEach((to, from) => {
  const store = useStore()
  store.setPageNum(1)
  // store.setTabIndex(0)
})



export default router
